<?php
namespace app\admin\model;

use think\Model;
use think\Db;
use think\facade\Config;
class Eventsclass extends Model
{   
   protected $connection = 'publicdata';
	/*查询数据 */
	public function get_data($page,$limit){

        $start=($page-1)*$limit;
        $list=Eventsclass::order('class_id', 'desc')->limit($start,$limit)->select()->toArray();
        $data['count']=Eventsclass::count();
        $data['list']=$list;

        return $data;
        
	}
	/*获取一条数据用于修改*/
	public function get_edit($id){
        $data=Eventsclass::where('class_id',$id)->find();
        return $data;  
	}
	/*新增*/
	public function insert_data($da){
      $Eventsclass = new Eventsclass;
		$result=$Eventsclass->save([
		    'title'  =>  trim($da['title']),
            'title_en'  =>  trim($da['title_en']),
            'seq'  =>  trim($da['seq'])
		]);
		return $result;
	}
	/*修改*/
	public function update_data($id,$da){

      $data = new Eventsclass;
      // save方法第二个参数为更新条件
      $result=$data->save([
          'title'  => $da['title'],
          'title_en'  => $da['title_en'],
          'seq'  => $da['seq']
      ],['class_id' => $id]);
      
      
		return $result;    
	}
	/*删除假动作实际为修改操作*/
	public function delete_data($id){
        $result=Eventsclass::where('class_id','=',$id)->delete();
		return $result;
	}
}
 